﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GZ.Entity;
using Newtonsoft.Json;
using System.Data;
public partial class myorders : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["gz_customer"] != null)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["start"]) && !String.IsNullOrEmpty(Request.QueryString["end"]))
                {
                    this.start.Value = Request.QueryString["start"];
                    this.end.Value = Request.QueryString["end"];
                }
                else
                {
                    this.start.Value = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");
                    this.end.Value = DateTime.Now.ToString("yyyy-MM-dd");
                }

                LoadCustomerOrders(this.start.Value, this.end.Value);
            }
            else
            {
                NotResult.Visible = true;
            }
        }
    }
    /// <summary>
    ///前台加载客户搜索历史订单
    /// </summary>
    public void LoadCustomerOrders(String start, String end)
    {
        EOrder orderAccessor = new EOrder();
        DataTable dtCustomerOrders = null;
        CookieUserObject user = JsonConvert.DeserializeObject<CookieUserObject>(Request.Cookies["gz_customer"].Value);
        dtCustomerOrders = orderAccessor.GetOrdersByCreateDate(Convert.ToDateTime(start), Convert.ToDateTime(end), Convert.ToInt32(user.Id));

        if (dtCustomerOrders != null && dtCustomerOrders.Rows.Count != 0)
        {
            rpt_Orders.DataSource = dtCustomerOrders;
            rpt_Orders.DataBind();
        }
        else
        {
            NotResult.Visible = true;
        }
    }

    /// <summary>
    /// 获取付款方式类型
    /// </summary>
    /// <param name="PaymentType"></param>
    /// <returns></returns>
    public string GetPaymentType(string PaymentType)
    {
        string str = string.Empty;
        switch (PaymentType)
        {
            case "1":
                str = "货到付款";
                break;
            case "2":
                str = "财付通";
                break;
            case "3":
                str = "支付宝";
                break;
            default:
                str = "货到付款";
                break;
        }
        return str;
    }


    public String OderState(Int32 orderState)
    {
        String state = String.Empty;
        switch (orderState)
        {
            case 6: state = "订单拒收"; break;
            case 5: state = "订单取消"; break;
            case 4: state = "订单完成"; break;
            case 3: state = "正在派送"; break;
            case 2: state = "已审核"; break;
            case 1: state = "未处理订单"; break;
        }
        return state;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Response.Redirect(string.Format("/myorders.aspx?start={0}&end={1}", start.Value, end.Value));
    }
}